package com.welab.springcloud.demo.goods.controller;

import com.welab.springcloud.demo.dto.Goods;
import com.welab.springcloud.demo.dto.ResponseResult;
import com.welab.springcloud.demo.goods.service.GoodsService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RefreshScope
@RestController
public class GoodsController {

    @Resource
    GoodsService goodsService;

    @GetMapping("/goods/{goodsId}")
    @ResponseBody
    public ResponseResult<Goods> getGoods(Integer goodsId) {
        return ResponseResult.success(goodsService.getGoods(goodsId));
    }

    @GetMapping(value = "/userGoods/{userId}")
    @ResponseBody
    public ResponseResult<List<Goods>> getUserGoods(Integer userId) {
        return ResponseResult.success(goodsService.getUserGoods(userId));
    }

}
